package com.example.file.utils;

/**
 * 文件大小工具类
 */
public class FileUnitUtils {
    /**
     * 文件字节大小转人类可读
     * @param fileSize
     * @return
     */
    public static String fileSize2Human(long fileSize) {
        String[] unit = {"B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB", "BB", "NB", "DB", "∞"};
        byte i = 0;
        while (true) {
            if (fileSize < 1024) {
                return fileSize + unit[i];
            }
            fileSize /= 1024;
            i++;
        }
    }

    public static void main(String[] args) {
        String s = fileSize2Human(200086786860L);
        System.out.println("s = " + s);
    }
}
